import ktools from 'ktools';
let tools = ktools.tools;
console.log(112);
console.log(tools);
class DeviceMotion {
    constructor() {
        this.init();
    }
    init() {
        let container2 = document.querySelector('.container2');
        if (this.isDeviceMotionEventSupported()) {
            window.addEventListener('devicemotion', shakeHandle);

            function shakeHandle() {
                const minTHRESHOLD = 20e-12;
                const maxTHRESHOLD = 9e-12;
                let currenTime = new Date().getTime();
                let x, y, z, last_x = 0,
                    last_y = 0,
                    last_z = 0,
                    last_time = 0;
                x = event.accelerationIncludingGravity.x;
                y = event.accelerationIncludingGravity.y;
                z = event.accelerationIncludingGravity.z;
                let speed = Math.abs((x + y + z - last_x - last_y - last_z)) / (currenTime - last_time);
                container2.innerHTML = `======================<br>motion:<br>acceleration:<br>x:${event.acceleration.x}<br>y:${event.acceleration.y}<br>z:${event.acceleration.z}<br> accelerationIncludingGravity:<br>x:${event.accelerationIncludingGravity.x}<br>y:${event.accelerationIncludingGravity.y}<br>z:${event.accelerationIncludingGravity.z}<br> interval:${event.interval}<br>speed1:${speed}<br>${100e-12}`;
                if (speed > maxTHRESHOLD) {
                    window.removeEventListener('devicemotion', shakeHandle);
                    tools.execCallBack();
                }
                last_x = x;
                last_y = y;
                last_z = z;
                last_time = currenTime;
            }
        } else {
            alert('devicemotion event not supported');
        }
        return this;

    }
    shake(cb, cb2) {

    }
    shakeAfter() {
        window.addEventListener('devicemotion', shakeHandle);
    }

    isDeviceMotionEventSupported() {
        if (window.DeviceMotionEvent) {
            return true;
        }
        return false;
    }
}
module.exports = DeviceMotion;
